function [WeiDist] = Principal_A2_n(Par2)
n = 50;

load ParEst_eh0_time0_Mex_guys ParEst_eh0_time0_Mex_guys
load W_time2_eh0_comp1.out
load stock_time2_eh0_comp1.out

Par1 = zeros(18,1);
Par1(1:13) = ParEst_eh0_time0_Mex_guys;
Par1(11) = 10^Par1(11);
Par1(12:13)=1000*Par1(12:13);
Par1(14) = 500*Par2(1);
Par1(15:18)=Par2(2:5);

w_mom=W_time2_eh0_comp1(1,:); % Read wage moments
meanwi_1=w_mom(1); meanwf_1=w_mom(2);   meanwi_2=w_mom(3);  meanwf_2=w_mom(4);  sdwi_1=w_mom(5); sdwf_1=w_mom(6);  sdwi_2=w_mom(7);   sdwf_2=w_mom(8);
p10wi_1=w_mom(9);  p10wf_1=w_mom(10); p10wi_2=w_mom(11); p10wf_2=w_mom(12); p25wi_1=w_mom(13); p25wf_1=w_mom(14); p25wi_2=w_mom(15); p25wf_2=w_mom(16); 
p50wi_1=w_mom(17); p50wf_1=w_mom(18); p50wi_2=w_mom(19); p50wf_2=w_mom(20); p75wi_1=w_mom(21); p75wf_1=w_mom(22); p75wi_2=w_mom(23); p75wf_2=w_mom(24); 
p90wi_1=w_mom(25); p90wf_1=w_mom(26); p90wi_2=w_mom(27); p90wf_2=w_mom(28); minwi_1=w_mom(29); minwf_1=w_mom(30); minwi_2=w_mom(31); minwf_2=w_mom(32); 
maxwi_1=w_mom(33); maxwf_1=w_mom(34); maxwi_2=w_mom(35); maxwf_2=w_mom(36);

wf_1=linspace(minwf_1,maxwf_1,n)';        % Wage in formal sector
wi_1=linspace(minwi_1,maxwi_1,n)';        % Wage in informal sector
wf_2=linspace(minwf_2,maxwf_2,n)';      % Wage in formal sector
wi_2=linspace(minwi_2,maxwi_2,n)';      % Wage in informal sector

wage_moments_data=[meanwi_1; meanwf_1; sdwi_1; sdwf_1]; % guys

stock_mom=stock_time2_eh0_comp1(1,:); % Read stocks
stock_ANT=stock_mom'; 
stock = [stock_ANT(1) + stock_ANT(2) + stock_ANT(3);...
    stock_ANT(4) + stock_ANT(6) + stock_ANT(7); ...
    stock_ANT(5) + stock_ANT(8) + stock_ANT(9)]; % guys

stock_mom_boot = zeros(100,3);
stock_mom_boot = [stock_time2_eh0_comp1(:,1)+stock_time2_eh0_comp1(:,2)+stock_time2_eh0_comp1(:,3),...
    stock_time2_eh0_comp1(:,4)+stock_time2_eh0_comp1(:,6)+stock_time2_eh0_comp1(:,7),...
    stock_time2_eh0_comp1(:,5)+stock_time2_eh0_comp1(:,8)+stock_time2_eh0_comp1(:,9)]; % guys
HHstates_data_boot=var(stock_mom_boot)';

w_mom_var=var(W_time2_eh0_comp1)';
meanwi_1v=w_mom_var(1); meanwf_1v=w_mom_var(2);   meanwi_2v=w_mom_var(3);  meanwf_2v=w_mom_var(4);  sdwi_1v=w_mom_var(5); sdwf_1v=w_mom_var(6);  sdwi_2v=w_mom_var(7);   sdwf_2v=w_mom_var(8);
p10wi_1v=w_mom_var(9);  p10wf_1v=w_mom_var(10); p10wi_2v=w_mom_var(11); p10wf_2v=w_mom_var(12); p25wi_1v=w_mom_var(13); p25wf_1v=w_mom_var(14); p25wi_2v=w_mom_var(15); p25wf_2v=w_mom_var(16); 
p50wi_1v=w_mom_var(17); p50wf_1v=w_mom_var(18); p50wi_2v=w_mom_var(19); p50wf_2v=w_mom_var(20); p75wi_1v=w_mom_var(21); p75wf_1v=w_mom_var(22); p75wi_2v=w_mom_var(23); p75wf_2v=w_mom_var(24); 
p90wi_1v=w_mom_var(25); p90wf_1v=w_mom_var(26); p90wi_2v=w_mom_var(27); p90wf_2v=w_mom_var(28); minwi_1v=w_mom_var(29); minwf_1v=w_mom_var(30); minwi_2v=w_mom_var(31); minwf_2v=w_mom_var(32); 
maxwi_1v=w_mom_var(33); maxwf_1v=w_mom_var(34); maxwi_2v=w_mom_var(35); maxwf_2v=w_mom_var(36);
 
wage_data_boot = [meanwi_1v; meanwf_1v; sdwi_1v; sdwf_1v]; % guys

boot_vector = [wage_data_boot; HHstates_data_boot]; % variance of moments
 
HHstates_data=stock; % [F,I,N]; % states

 % solve dist of wage offers, value functions and simulate trajectory
[Ff_1,ff_1,Fi_1,fi_1]=solve_wage_offer_dist(Par1,wf_1,wi_1,n);
[Wf,Wi,Wn,iterVF]=solve_value_function_A1(Par1,Ff_1,wf_1,Fi_1,wi_1,n);
[HHstates,wage_moments,transitions]=data_simulation_A12_end(Par1,ff_1,wf_1,fi_1,...
    wi_1,Wf,Wi,Wn);
iterVF
if iterVF>=401
WeiDist = 1000^10;
else
MatCov = zeros(7);
for i=1:7
    MatCov(i,i) = 1/(boot_vector(i));
end
MomSim = zeros(7,1);
MomData = zeros(7,1);
MomData = [wage_moments_data; HHstates_data];
MomSim =  [wage_moments(1:4); HHstates];
WeiDist = 15*(transpose(MomData - MomSim))*MatCov*(MomData-MomSim)
end
